#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include "Transaction.h"
#include "Products.h"
#include "Usb.h"
#include "OrderProduct.h"

using namespace std;

#ifndef POSMENU_H
#define POSMENU_H

class PosMenu {

private:
	vector<Products *> products;
	vector<OrderProduct *> shoppingCart;
public:
	PosMenu();

	// browse all the items
	void browseAllItems();

	// browse specific type items
	void browseSpecificItems(string type);

	// browse the stocks that below threshold value input by the user.
	void browseItemsBelowThresholdValue();

	// display specific format from a specific product list
	void displayProductsFromSpecificList( vector <Products *> products);

	// display specific type items
	void displaySpecificItems(Products *derivedPtr);

	////////////////////////////////////////////////////////////////

	// search item by product id
	void searchItemByPid(string pid);

	// search item by brand
	void searchItemByBrand(string brand);

	// search item by stock
	void searchItemByStock(int stock);

	// search item by price
	void searchItemByPrice(int price);

	////////////////////////////////////////////////////////////////

	// restock an item
	void restockItem(Products *product, int quantity);

	/////////////////////////////////////////////////////////////////

	// sort the items
	void sortProductsList();

	// sort item by price
	void sortByPrice();

	// sort by brand
	void sortByBrand();

	// sort by stock
	void sortByStock();

	// swap product in productlist
	void swap(vector<Products *> productsList, int p1, int p2);

	//////////////////////////////////////////////////////////////////
	/////////////////////// Shopping Cart

	// choose items and pick up into the shopping cart
	void selectProductsIntoShoppingCart();

	// browse the shopping cart items
	void browseAllItemsInShoppingCart();

	// clear the shopping cart items
	void clearShoppingCart();


	// deduce the quantity of the products from the list
	void deduceQuantity(string  pid, int quantity);

	//////////////////////////////////////////////////////////////////
	/////////////////////// Transcation

	// purchase items
	void createTransaction();

	// check transaction details by invoice number.
	void viewInvoiceDetail();

	// write the transaction into the Transaction.txt
	void writeTransactionIntoTxt(Transaction * transaction);

	// retrieve the transaction by the invoice number
	Transaction * readTransactionByInvoiceNo(string invoiceNo);

	// retrieve all transactions
	vector<Transaction *> readAllTransactions();

	// view the saved transaction
	void  viewTheLatestInvoice();

	// view the total amount of momey received
	void viewSaleReport();

	//////////////////////////////////////////////////////////////////
	// set products list
	void setProductsList(vector<Products *> products);

	// get product list
	vector<Products *> getProductsList(); 

	// set shopping cart 
	void setShoppingCart(vector<OrderProduct *> shoppingCart);

	// get product list
	vector<OrderProduct *> getShoppingCart(); 

	// get the actucally size of display list
	int displayListSize(vector<Products *> displayList);


	/////////////////////////////////////////////////////////////////

	// Validation

	// check the itemNo is existing in the product list
	int isExistProducts(int itemNo);

	// check the product is exsiting in the shopping cart
	int isExistProductInShoppingCart(Products * product);

};
// Other assistant method for resolving the technical problems

// Trim the whitespace of string
string trim(string str);

// Integer to String
string IntToString(int a);

// Method for split the string into vector<string> by the delim
vector<string> &split(const string &s, char delim,vector<string> &elems);
vector<string> split(const string &s, char delim);

#endif